package com.atguigu.lease.web.app.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;

import java.util.Objects;

public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
        for (ItemType value : ItemType.values()) {
            if (Objects.equals(value.getCode(), Integer.valueOf(source))){
                return value;
            }
        }
        throw new IllegalArgumentException("非法参数异常，只支持1,2类型！！！");
    }
}
